<?php
/**
 * 1.隐藏index.php
 * 2.获取url
 * 3.返回对应控制器和方法
 * User: @fs
 * Date: 2017/9/10
 * Time: 19:51
 */
namespace core\lib;
use      core\lib\conf;

class route
{

    public $ctrl;
    public $action;

    public function __construct()
    {
        // p($_SERVER['REDIRECT_URL']);

        if (isset($_SERVER['REDIRECT_URL']) && $_SERVER['REDIRECT_URL'] != '/') {
            $path       = trim($_SERVER['REDIRECT_URL'], '/');
            $patharr    = explode('/', $path);
            $this->ctrl = isset($patharr[0]) ? $patharr[0] : conf::get('ctrl','conf');
            unset($patharr[0]);
            if (isset($patharr[1])) {
                $this->action = $patharr[1];
                unset($patharr[1]);
            } else {
                $this->action = conf::get('action','conf');
            }



            //如果不是pathinfo 模式,开始处理
            if (!empty($_GET)) {
                foreach ($_GET as $key => $value) {
                    unset($_GET[$key]);
                }
            }


            //这边开始处理url
            //多余部分搞成get
            $count = count($patharr) + 2;
            $i     = 2;
            while ($i < $count) {
                if (isset($patharr[$i + 1])) {
                    $_GET[$patharr[$i]] = $patharr[$i + 1];

                }

                $i = $i + 2;
            }


        } else {
            $this->ctrl   = conf::get('ctrl','conf');
            $this->action = conf::get('action','conf');
        }

    }
}
